package com.yxt.controller;

import com.yxt.pojo.ResponseEntity;
import com.yxt.pojo.TbUser;
import com.yxt.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
@Api(tags = "用户权限")
public class UserController {

        @Resource
        UserService userService;

        /**
         * 登录
         * @param tbUser
         * @return
         */
        @PostMapping("login")
        @ApiOperation("登录")
        public ResponseEntity login(@RequestBody TbUser tbUser, HttpServletRequest request){
                return  userService.login(tbUser,request);
        }

        /**
         * 注册
         * @param tbUser
         * @return
         */
        @PostMapping("register")
        @ApiOperation("注册")
        public ResponseEntity register(@RequestBody TbUser tbUser){
                return userService.register(tbUser);
        }

        /**
         * 用户注销
         * @param
         * @return
         */
        @PostMapping("del/{uid}")
        @ApiOperation("用户注销")
        public ResponseEntity del(@PathVariable(value = "uid") Integer uid){
                return  userService.del(uid);
        }

        /**
         * 管理员删除用户
         * @param id
         * @param uid
         * @return
         */
        @PostMapping("gdel/{id}/{uid}")
        @ApiOperation("管理员删除用户")
        public ResponseEntity gdel(@PathVariable(value = "id") Integer id ,@PathVariable(value = "uid") Integer uid){
                return  userService.gdel(id,uid);
        }

        /**
         * 用户权限角色信息列表
         * @param tbUser
         * @return
         */
        @PostMapping("list")
        @ApiOperation("列表")
        public ResponseEntity list(@RequestBody TbUser tbUser){
                return userService.list(tbUser);
        }

        /**
         * 管理员更改用户权限
         * @param id
         * @param pid
         * @param uid
         * @return
         */
        @PostMapping("update/{id}/{pid}/{uid}")
        @ApiOperation("管理员修改权限")
        public ResponseEntity update (@PathVariable(value = "id") Integer id ,@PathVariable(value = "pid") Integer pid,@PathVariable(value = "uid") Integer uid){
                return userService.update(pid,id,uid);
        }
}
